<?php
import("data.db.DbAbstractTable");
import("data.db.DbFactory");
import("data.logic.lingvo.Bundle");

class DbBundle extends DbAbstractTable {
	public $className = "data.logic.lingvo.Bundle";
	const CLASS_NAME = "data.logic.lingvo.Bundle";
	
	const DEFAULT_LANGUAGE	=  "en";
	//
	// SQL Table description section
	//
	const TB_TABLENAME	= "pd_bundle";
	const TB_I			= 'bn';
	
	const TB_VALUE		= 'bn_value';
	const TB_KEY		= 'bn_key';
	const TB_LANG		= 'bn_locale';
	
	public static function _get_TABLENAME() {return self::TB_TABLENAME;}
	public static function _get_ID() {return self::TB_I."_id";}
	public static function _get_SUFFIX() {return self::TB_I;}
	//
	//
	
	// properties
	public $value;
	public $key;
	public $language;
	
	public function __construct($noinit=false) {
		parent::__construct($noinit);
	}
	
	function setLanguage($lang) {
		$this->language = $lang;
	}
	function getLanguage() {
		return $this->language;
	}
	
	function getKey() {
		return $this->key;
	}
	function setKey($value) {
		$this->key = $value;
	}
	
	function getValue() {
		return $this->value;
	}
	function setValue($value) {
		$this->value = $value;
	}
	
	// restore
	function fillEntity($arrResult) {
		parent::fillEntity($arrResult);
		$this->setValue($arrResult[self::TB_VALUE]);
		$this->setKey($arrResult[self::TB_KEY]);
		$this->setLanguage($arrResult[self::TB_LANG]);
	}
	
	//store
	function fillFields() {
		parent::fillFields();
		$this->fildsForStore[self::TB_VALUE] = "'".$this->getValue()."'";
		$this->fildsForStore[self::TB_KEY] = "'".$this->getKey()."'";
		$this->fildsForStore[self::TB_LANG] = "'".$this->getLanguage()."'";
	}
	
	public static function findAllByLang($lang_id=null) {
		if (!$lang_id) $lang_id = DbBundle::DEFAULT_LANGUAGE;
		return parent::__selectByCriteria(self::TB_LANG."='$lang_id'",self::CLASS_NAME);
	}
	
	public static function findByKey($key, $lang_id=null) {
		if (!$lang_id) $lang_id = DbBundle::DEFAULT_LANGUAGE;
		return parent::__selectByCriteria(self::TB_KEY."='".$key."' and ".self::TB_LANG."='".$lang_id."'", self::CLASS_NAME);
	}
	
	// same for all classes
    public static function findAll() {return parent::findAll(self::CLASS_NAME);}
    public static function findById($id) {return parent::findById($id, self::CLASS_NAME);}
}
?>